const Models = {}
const Mongoose = require('./Mongoose')
function model (name) {
  const modelPath = `${yy.path.root}/src/common/model/${name}`
  const modelName = (name.indexOf('/') > -1) ? name.replace(/\//g, '_') : name
  if (!Models[modelName]) {
    try {
      const Cls = require(modelPath)
      Models[modelName] = new Cls(modelName)
    } catch (e) {
      Models[modelName] = new Mongoose(modelName)
    }
  }
  return Models[modelName]
}
module.exports = {
  model, Mongoose
}
